package com.zd.web.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.zd.entity.Novel2;
import com.zd.entity.NovelAndCollection;
import com.zd.service.MessageService;
import com.zd.service.impl.MessageServiceImpl;

/**
 * Servlet implementation class MessageServlet
 */
@WebServlet("/MessageServlet2")
public class MessageServlet2 extends HttpServlet {
	private static final long serialVersionUID = 1L;
   
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		request.setCharacterEncoding("UTF-8");
		String chapterid=request.getParameter("chapterId");
		int chapterId=Integer.parseInt(chapterid);
		String c=request.getParameter("novelId");
		int novelId=Integer.parseInt(c);
		request.setAttribute("novelId", novelId);
		MessageService messageservice=new MessageServiceImpl();
		List<Novel2> list=messageservice.message(Integer.parseInt(chapterid));
		String chapterNum=request.getParameter("chapterNum");
		System.out.println(chapterNum);
		request.setAttribute("chapterNum", chapterNum);
		request.setAttribute("list", list);
		int chaptercount=messageservice.chaptercount(novelId);
		request.setAttribute("chaptercount", chaptercount);
		//查一遍第几章
		int num=messageservice.getZhangJie(novelId,chapterId);
		System.out.println(num+"第几章");
		request.setAttribute("num",num);
		request.getRequestDispatcher("message2.jsp").forward(request, response);
	}
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
